<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>bms</title>
    <link rel="stylesheet" type="text/css" href="/themes/default/easyui.css" id="swicth-style">
    <link rel="stylesheet" type="text/css" href="/css/icon.css">
    <link rel="stylesheet" type="text/css" href="/css/common.css">
    <link rel="stylesheet" type="text/css" href="/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="/themes/color.css">
    <script type="text/javascript" src="/js/jquery.min.js"></script>
    <script type="text/javascript" src="/js/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/js/jquery.cookie.js"></script>
    <script type="text/javascript" src="/js/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="/js/common.js"></script>
</head>

<body class="easyui-layout" style="padding:5px">
<fieldset>
    <legend>信息查询</legend>
    <form id="ffSearch" method="post">
        <div id="searchBar">
            <table cellspacing="0" cellpadding="0">
                <tr>

                    <td colspan="2">
                        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="onSearch()">查询</a>&nbsp;&nbsp;
                        <!--<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-clear'" onclick="onClear()">重置</a>-->
                    </td>
                </tr>
            </table>
        </div>
    </form>
</fieldset>

<table id="dg"></table>



<script type="text/javascript">
    $(function () {
        var dg = $('#dg').datagrid();
        dg.datagrid({
            url: '/v1/api0/logs',
            columns: [[
//                {field: 'ck', checkbox: true},
                {field: 'name', title: '路径', width: 300},
                {field: 'level', title: '等级', width: 50},
                {
                    field: 'action', title: '操作', width: 120, formatter: function (value, row, index) {
                    return '<a href="javascript:void(0)" class="easyui-linkbutton" onclick="changeInfo(\'' + row.name + '\')">INFO</a> | ' +
                        '<a href="javascript:void(0)" class="easyui-linkbutton" onclick="changeDebug(\'' + row.name + '\')">DEBUG</a>'
                }
                }
            ]],
            title: '日志级别',
            pagination: false,
            iconCls: 'icon-application_view_detail',
            singleSelect: false

        });

        var heightMargin = $("#searchBar").height() + 45;
        $('#dg').resizeDataGrid(heightMargin, 0, 0, 0);
        $(window).resize(function () {
            $('#dg').resizeDataGrid(heightMargin, 0, 0, 0);
        });
    });

    function onSearch() {
        var queryParams = $('#ffSearch').serializeObject();
        $('#dg').datagrid({
            url: '/v1/api0/logs',
            queryParams: queryParams
        });
    }

    function onClear() {
        $('#ffSearch').form('clear');
        $('#statusSelect').combobox('setValue', '0');
        onSearch();
    }


    function closeWindow() {
        $('#addOrEdit').window('close');
        $('#bind').window('close');
    }


    function changeInfo(name) {
        return {
            type: "post",
            url: '/v1/api0/logs/set',
            data: {
                name:name,
                level:"INFO"
            },
            datatype: "json",
            beforeSend: function () {
                $('#dg').datagrid('loading');
            },
            success: function (data) {
                if (data.code == 200) {
                    $('#dg').datagrid('reload');
                    top.window.showMessage();
                    closeWindow();
                } else {
                    top.window.showMessage(data.msg);
                    $('#dg').datagrid('loaded');
                }
            },
            error: function () {
                $('#dg').datagrid('loaded');
            }
        }
    }


    function changeDebug(name) {
        var url = "/v1/api0/logs/set";
        var data = {
            name:name,
            level:"DEBUG"
        };
        $.ajax(ajaxOption(url, data))
    }


    function ajaxOption(url, data) {
        return {
            type: "POST",
            url: url,
            data: JSON.stringify(data),
            datatype: "json",
            beforeSend: function () {
                $('#dg').datagrid('loading');
            },
            success: function (data) {
                if (data.code == 200) {
                    $('#dg').datagrid('reload');
                    top.window.showMessage();
                    closeWindow();
                } else {
                    top.window.showMessage(data.msg);
                    $('#dg').datagrid('loaded');
                }
            },
            error: function () {
                $('#dg').datagrid('loaded');
            }
        }
    }
</script>
</body>
</html>
